<%@ page import="org.springframework.context.ApplicationContext" %>
<%@ page import="static org.apache.struts2.ServletActionContext.getServletContext" %>
<%@ page import="org.springframework.web.context.WebApplicationContext" %>
<%@ page import="com.ld.xuanKe.service.UserService" %>
<%@ page import="com.ld.xuanKe.service.impl.UserServiceImpl" %>
<%@ page import="com.ld.xuanKe.entity.User" %><%--
  Created by IntelliJ IDEA.
  User: 刘邓
  Date: 2023-12-09
  Time: 17:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
  <title>增加课程信息</title>
  <link rel="stylesheet" type="text/css" href="/form.css" />
</head>
<body>
<%
  ApplicationContext applicationContext = (ApplicationContext) getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
  UserService userService = (UserServiceImpl) applicationContext.getBean(UserService.class);
  Integer id = Integer.parseInt(request.getParameter("id"));
  User user = userService.querySingle(id);
  session.setAttribute("account",user.getAccount());
%>
<form action="/user/update" class="container">

  <h2>修改学生信息</h2>
  <input type="text" name="id" value="<%=user.getId()%>" class="form-control" hidden>
  <input type="text" name="status" value="<%=user.getStatus()%>" class="form-control" hidden>
  <input type="text" name="password" value="<%=user.getPassword()%>" class="form-control" hidden>
  <div class="form-group">

    <label for="username">学生名:</label>

    <input type="text" name="username" value="<%=user.getUsername()%>" id="username" class="form-control">

  </div>

  <div class="form-group">

    <label for="account">学号:</label>

    <input type="text" name="account" id="account" value="<%=user.getAccount()%>" class="form-control">

  </div>
  <div style="text-align: center">

    <button type="submit" id="toUpdate" style="width: 100px;height: 50px;background-color: #fff" class="btn btn-primary">提交</button>

  </div>

</form>

</body>
<script>
  let toUpdate = document.getElementById("toUpdate");
  toUpdate.addEventListener("click",(evt)=>{
    let username_str=document.getElementById("username").value;
    if(username_str===null||username_str===""){
      alert("请输入学生名");
      evt.preventDefault();
      return;
    }
    let account_str=document.getElementById("account").value;
    if(account_str===null||account_str===""){
      alert("请输入学号");
      evt.preventDefault();
      return;
    }
  })
</script>
</html>
